import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:path/path.dart' as path;

class HttpAttachmentService {
  /// 账单列表
  static Future<Response> createAttachment(String filePath,
      {int ocr,
      String preOcrText,
      String category,
      ProgressCallback onSendProgress}) async {
    final file =
        await BaseConfig.httpBase.formFile(filePath, path.basename(filePath));

    return BaseConfig.httpBase.postForm(
        '/api/attachments',
        {
          'file': file,
          if (ocr != null) ...{'ocr': ocr},
          if (preOcrText != null) ...{'pre_ocr_text': preOcrText},
          if (category != null) ...{'category': category}
        },
        onSendProgress: onSendProgress);
  }
}
